<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue_03</title>
    <style>
        *{
            padding: 0;margin: 0;
        }
        .page{
            width: 250px;
            height: 20px;      
        }
        .page .prev{
            float: left;
            margin-left: 5px;
            width: 50px;
            height: 20px;
            line-height: 20px;
        }
        .page .content{
            float: left;
        }
        .page .item{
            float: left;
            color: blanchedalmond;
            line-height: 20px;
            text-align: center;
            background-color: black;
            margin-left: 5px;
            width: 20px;
            height: 20px;
        }
        .page .next{
            float: left;
            margin-left: 5px;
            width: 50px;
            height: 20px;
            line-height: 20px;
        }
        .page .active{
            color: red;
        } 
        button{
            float: left;
            margin-left: 5px;
            width: 50px;
            height: 20px;
            line-height: 20px;
        }
    </style>
</head>
<body>
    <div class="page" id="page">
        <!-- <button class="prev">上一页</button>

        <div class="content">
            <div class="item">1</div>
            <div class="item">2</div>
            <div class="item">3</div>
            <div class="item">4</div>
            <div class="item">5</div>
        </div>
        
        <button class="next">下一页</button> -->
    </div>
    
</body>
<script>
    
    
    function page(option){
        this.ele = document.querySelector(option.el);
        this.ele.className = "page";
        this.create();    //方法
        this.data = option.data;
        this.bindData();
    }



    page.prototype.bindData = function(){
        this.allpage = Math.ceil(this.data.total/this.data.shownum);     //全部页数

        let start = 1;

        let end = this.allpage>this.data.showpage?this.data.showpage:this.allpage;

        for(let i = start; i <= end; i++){     //循环添加元素
            let item = document.createElement("div");
            item.className = "item";
            console.log(i)
            item.innerHTML = i;
            this.content.appendChild(item);

        }

    }
    
    page.prototype.create = function(){
        this.prevBtn = document.createElement("button");
        this.prevBtn.innerHTML = "上一页";
        this.ele.appendChild(this.prevBtn);

        this.content = document.createElement("div");
        this.content.className = "content"
        this.ele.appendChild(this.content);

        this.nextBtn = document.createElement("button");
        this.nextBtn.innerHTML = "下一页";
        this.ele.appendChild(this.nextBtn);

    }
    
    
    new page({
        el:"#page",
        data:{
            total:101,
            shownum:10,
            showpage:5,
        }
     
    })




</script>
</html>